import React from 'react'
import { useSelector,useDispatch,connect } from 'react-redux'

const Home = (props) => {
    console.log(props)
    const list = useSelector((state)=>state.home.list);
    // const {list} = useSelector((state)=>state)     //两种获取形式

    const dispatch = useDispatch();
    const add = () =>{
        dispatch({type:'add_item',payload:200})  //type名为add_item

    }
    return (
        <div>
            首页<button onClick={add}>添加</button>
            <ul>
                {
                    list.map(item=><li>{item}</li>)
                }
            </ul>
        </div>
    )

}

const mapStateToProps = state=>state.home;

export default connect(mapStateToProps)(Home)       //connect的返回值是一个高阶组件
